package com.solution.admin.point.controller;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.solution.admin.point.constants.PointConstants.ApproveStatus;
import com.solution.admin.point.constants.PointConstants.IsYesNo;
import com.solution.admin.point.constants.PointConstants.PointImportOperateType;
import com.solution.admin.point.constants.PointConstants.PointOperateType;
import com.solution.admin.point.constants.PointConstants.PointUseFlag;
import com.solution.admin.point.entity.PointEntity;
import com.solution.admin.point.entity.PointImportEntity;
import com.solution.admin.point.service.PointImportService;
import com.solution.admin.point.service.PointService;
import com.solution.common.constants.PublicStatus.IS_DELETE;
import com.solution.common.constants.PublicStatus.SysCode;
import com.solution.common.constants.PublicStatus.SysSymbol;
import com.solution.common.controller.BaseController;
import com.solution.common.entity.BaseReturn;
import com.solution.common.page.JSONGrid;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;
import com.solution.common.utils.UUIDUtil;
import com.solution.common.utils.importExcel.ExcelUtil;
import com.solution.common.utils.string.StringUtil;

/**
 * 积分导入信息web控制层
 * 
 * @author xu_cc
 * @date 2017-10-20 14:19:50
 */
@RequestMapping("/pointImport")
@Controller
public class PointImportController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(PointImportController.class);

	@Autowired
	PointImportService pointImportService;

	@Autowired
	PointService pointService;

	/**
	 * 批量删除积分调整记录（只能删除待审核的数据）
	 * 
	 * @param request
	 * @param id
	 * @return BaseReturn
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年10月24日 下午5:58:40
	 */
	@RequestMapping("/doDelPointImport")
	@ResponseBody
	public BaseReturn doDelPointImport(HttpServletRequest request, String idArrStr) {
		BaseReturn result = new BaseReturn();
		try {
			StringBuffer message = new StringBuffer();
			int success = 0;
			int failed = 0;
			String[] dataIdArr = idArrStr.split(SysSymbol.COMMA);
			if (null != dataIdArr && dataIdArr.length > 0) {
				for (String idStr : dataIdArr) {
					if (StringUtil.isEmpty(idStr)) {
						continue;
					} else {
						PointImportEntity pointImport = pointImportService.getPointImportById(Long.parseLong(idStr));
						// 如果获取的数据为空、审核状态不是待审核、或者数据标识已删除，则失败
						if (null == pointImport || !ApproveStatus.WAIT_APPROVE.equals(pointImport.getApproveStatus())
						        || IS_DELETE.DELETED.getId().equals(pointImport.getIsDelete())) {
							message.append("客户编号：").append((null != pointImport ? pointImport.getCustomerId() : "记录失效；")).append("删除失败！");
							failed++;
						} else {
							int rows = pointImportService.deletePointImportById(pointImport.getId());
							if (rows > 0) {
								success++;
							} else {
								failed++;
							}
						}
					}
				}
				String msg = "积分调整数据删除完成。";
				if (success > 0) {
					msg += "成功：" + success + "条！";
				}
				if (failed > 0) {
					msg += "失败：" + failed + "条！";
				}
				msg += message.toString();
				result.setMsg(msg);
				result.setCode(SysCode.SUCCESS);
				return result;
			} else {
				result.setCode(SysCode.FAILED);
				result.setMsg("请先选择需要删除的数据！");
				return result;
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(SysCode.ERROR);
			result.setMsg("删除积分调整信息异常！");
			return result;
		}
	}

	/**
	 * 审核（批量审核、全部审核通过）
	 * 
	 * @param request
	 * @param idArrStr
	 * @param isAll
	 * @return BaseReturn
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年11月8日 下午2:45:35
	 */
	@RequestMapping("/doAudit")
	@ResponseBody
	public BaseReturn doAudit(HttpServletRequest request, String idArrStr, String isAll, Integer approveStatus, String approveRemark) {
		BaseReturn result = new BaseReturn();
		StringBuffer message = new StringBuffer();
		int success = 0;
		int failed = 0;
		try {
			String userName = getUserName();
			// 判断是否全部审核
			if (IsYesNo.YES.equals(isAll)) {
				// 全部审核
				// 获取所有待审核、未删除的积分调整数据集合
				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("approveStatus", ApproveStatus.WAIT_APPROVE);
				List<PointImportEntity> dataList = pointImportService.listPointImport(paramMap);
				if (null != dataList && dataList.size() > 0) {
					PointImportEntity modifyPointImport = new PointImportEntity();
					for (PointImportEntity pointImport : dataList) {
						boolean isSuccess = doAuditSingle(pointImport, modifyPointImport, message, approveStatus, approveRemark, userName);
						if (isSuccess) {
							success++;
						} else {
							failed++;
						}
					}
					// 最后的返回
				} else {
					result.setCode(SysCode.FAILED);
					result.setMsg("没有需要审核的积分调整记录！");
					return result;
				}
			} else {
				String[] dataIdArr = idArrStr.split(SysSymbol.COMMA);
				if (null != dataIdArr && dataIdArr.length > 0) {
					PointImportEntity modifyPointImport = new PointImportEntity();
					for (String idStr : dataIdArr) {
						if (StringUtil.isEmpty(idStr)) {
							continue;
						} else {
							PointImportEntity pointImport = pointImportService.getPointImportById(Long.parseLong(idStr));
							boolean isSuccess = doAuditSingle(pointImport, modifyPointImport, message, approveStatus, approveRemark, userName);
							if (isSuccess) {
								success++;
							} else {
								failed++;
							}
						}
					}
					// 最后的返回
				} else {
					result.setCode(SysCode.FAILED);
					result.setMsg("请先选择需要审核的积分调整记录！");
					return result;
				}
			}
			String msg = "积分调整数据审核完成。";
			if (success > 0) {
				msg += "成功：" + success + "条！";
			}
			if (failed > 0) {
				msg += "失败：" + failed + "条！";
			}
			msg += message.toString();
			result.setMsg(msg);
			result.setCode(SysCode.SUCCESS);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(SysCode.ERROR);
			result.setMsg("数据审核出现异常，请重试！");
			return result;
		}
	}

	/**
	 * 审核操作（针对单一记录操作）
	 * 
	 * @param pointImport
	 * @param modifyPointImport
	 * @param message
	 * @param approveStatus
	 * @param approveRemark
	 * @param userCode
	 * @return boolean
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年11月8日 下午5:10:58
	 */
	private boolean doAuditSingle(PointImportEntity pointImport, PointImportEntity modifyPointImport, StringBuffer message, Integer approveStatus,
	        String approveRemark, String userCode) {
		try {
			// 如果获取的数据为空、审核状态不是待审核、或者数据标识已删除，则失败
			if (null == pointImport || !ApproveStatus.WAIT_APPROVE.equals(pointImport.getApproveStatus())
			        || IS_DELETE.DELETED.getId().equals(pointImport.getIsDelete())) {
				message.append("客户编号：").append((null != pointImport ? pointImport.getCustomerId() : "记录失效；")).append("数据获取失败");
				return false;
			} else {
				// 审核意见赋值
				modifyPointImport.setId(pointImport.getId());
				modifyPointImport.setApproveRemark(approveRemark);
				modifyPointImport.setMobile(userCode);
				if (ApproveStatus.APPROVE_FAILED.equals(approveStatus)) {
					// 审核拒绝（驳回），直接该本条数据信息就可
					modifyPointImport.setApproveStatus(ApproveStatus.APPROVE_FAILED);
				} else if (ApproveStatus.APPROVE_SUCCESS.equals(approveStatus)) {
					// 审核通过成功（通过），增减系统积分
					modifyPointImport.setApproveStatus(ApproveStatus.APPROVE_SUCCESS);
					// 操作标识
					int operateFlag = PointOperateType.getFlagById(pointImport.getOperateType());
					// 执行增减积分调整操作
					pointService.doOperatePointCommon(pointImport.getCustomerId(), operateFlag, String.valueOf(pointImport.getOperateType()),
					        pointImport.getOperatePoint(), pointImport.getAdjustReason(), null, null, userCode, true);
				} else {
					throw new Exception("未知的审核结果！");
				}
				// 最后更新该记录的审核状态
				int rows = pointImportService.updatePointImport(modifyPointImport);
				if (rows > 0) {
					return true;
				} else {
					return false;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 跳转积分导入信息查询页面
	 * 
	 * @param PointImport
	 *            接收界面查询条件参数
	 * @param request
	 *            请求对象
	 * @return 返回对应的页面视图
	 * @author xu_cc
	 * @date 2017-10-20 14:19:50
	 */
	@RequestMapping("/toListPointImportPage")
	public String toListPointImportPage(PointImportEntity pointImport, HttpServletRequest request, Model model) {
		try {
			// // 开始日期
			// int beginDay =
			// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_BEGIN_DAY));
			// // 结束日期
			// int endDay =
			// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_END_DAY));
			// // 调整日期
			// int modifyDay =
			// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_MODIFY_DAY));
			// // 今日日期
			// Calendar ca = Calendar.getInstance();
			// int today = ca.get(Calendar.DATE);
			// model.addAttribute("beginDay", beginDay);
			// model.addAttribute("endDay", endDay);
			// model.addAttribute("modifyDay", modifyDay);
			// model.addAttribute("today", today);
			// // 判断页面是否进行上传操作，是否可以删除、编辑
			// if (today >= beginDay && today <= endDay) {
			// // 今天在系统配置允许修改时间内，可以操作
			// model.addAttribute("impFlag", SysCode.SUCCESS);
			// } else {
			// model.addAttribute("impFlag", SysCode.FAILED);
			// }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "point/pointImport_list";
	}

	/**
	 * 校验日期，是否允许修改、删除、导入
	 * 
	 * @return boolean
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年11月1日 上午10:55:51
	 */
	// @Deprecated
	// private boolean checkDay() {
	// try {
	// // 开始日期
	// int beginDay =
	// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_BEGIN_DAY));
	// // 结束日期
	// int endDay =
	// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_END_DAY));
	// // 今日日期
	// Calendar ca = Calendar.getInstance();
	// int today = ca.get(Calendar.DATE);
	// // 判断页面是否进行上传操作，是否可以删除、编辑
	// if (today >= beginDay && today <= endDay) {
	// // 今天在系统配置允许修改时间内，可以操作
	// return true;
	// } else {
	// return false;
	// }
	// } catch (Exception e) {
	// e.printStackTrace();
	// return false;
	// }
	// }

	/**
	 * 修改积分导入信息
	 * 
	 * @param request
	 *            请求对象
	 * @param pointRuleEntity
	 *            积分规则设置信息实体
	 * @return
	 * @author xu_cc
	 * @date 2017-10-20 14:25:42
	 */
	@RequestMapping("/modifyPointImport")
	@ResponseBody
	public BaseReturn modifyPointImport(HttpServletRequest request, PointImportEntity pointImport) {
		BaseReturn result = new BaseReturn();
		try {
			pointImport.setCreater(getUserName());
			int rows = pointImportService.updatePointImport(pointImport);
			if (rows > 0) {
				result.setCode(SysCode.SUCCESS);
				result.setMsg("积分调整信息修改成功！");
			} else {
				result.setCode(SysCode.SUCCESS);
				result.setMsg("积分调整信息修改失败！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(SysCode.ERROR);
			result.setMsg("积分调整信息修改异常！");
		}
		return result;
	}

	/**
	 * 导入
	 * 
	 * @param request
	 * @param model
	 * @return String
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年10月24日 上午10:58:03
	 */
	@RequestMapping("/pointImp")
	public String pointImp(HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam("file") MultipartFile multfile) {
		StringBuffer msg = new StringBuffer();
		try {
			msg = doCheck(multfile);
			if (StringUtil.isNotNull(msg.toString())) {
				return toListPageFromUpload(model, msg.toString());
			}
			List<Map<String, String>> mapList = null;
			try {
				// 先以xlsx，poi读取2007的方式读取
				mapList = ExcelUtil.readSheet2007(multfile, 0);
				if (null == mapList) {
					// 以2003，xls，jxl的方式读取
					File file = ExcelUtil.multipartToFile(multfile);
					mapList = ExcelUtil.readSheet(file, 0);
				}
			} catch (Exception e) {
				msg.append("文件读取数据异常！" + e.getMessage());
				e.printStackTrace();
			}
			if (null != mapList && mapList.size() > 0) {
				// 正常title
				Map<String, String> headMap = new HashMap<String, String>();
				headMap.put("客户编号", "客户编号");
				headMap.put("客户单位", "客户单位");
				headMap.put("客户名称", "客户名称");
				headMap.put("手机号码", "手机号码");
				headMap.put("操作类型", "操作类型");
				headMap.put("操作积分", "操作积分");
				headMap.put("原因", "原因");
				// 读取到的title
				Map<String, String> titleMap = mapList.get(0);
				// 标题校验
				for (String key : headMap.keySet()) {
					if (!titleMap.containsKey(key)) {
						msg.append("标题校验失败，请上传正确的文件！");
						return toListPageFromUpload(model, msg.toString());
					}
				}
				// 标题校验成功，开始提取数据组装
				List<PointImportEntity> pointImportList = doGetDataFromMapList(mapList, msg);
				// 如果错误有错误信息，直接返回页面
				if (StringUtil.isNotNull(msg.toString())) {
					toListPageFromUpload(model, msg.toString());
				} else {
					// 开始执行导入数据
					doExecDataToDB(pointImportList, msg);
				}
			} else {
				msg.append("未读取到数据！");
			}
		} catch (Exception e) {
			msg.append("文件导入异常！" + e.getMessage());
			e.printStackTrace();
		}
		return toListPageFromUpload(model, msg.toString());
	}

	/**
	 * 上传操作转回列表页
	 * 
	 * @param model
	 * @param msg
	 * @return String
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年10月27日 下午3:36:24
	 */
	private String toListPageFromUpload(Model model, String msg) {
		try {
			// 保存错误信息
			model.addAttribute("msg", msg.toString());
			// // 开始日期
			// int beginDay =
			// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_BEGIN_DAY));
			// // 结束日期
			// int endDay =
			// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_END_DAY));
			// // 调整日期
			// int modifyDay =
			// Integer.parseInt(PublicConfigUtil.readConfig(POINT_IMPORT_MODIFY_DAY));
			// // 今日日期
			// Calendar ca = Calendar.getInstance();
			// int today = ca.get(Calendar.DATE);
			// model.addAttribute("beginDay", beginDay);
			// model.addAttribute("endDay", endDay);
			// model.addAttribute("modifyDay", modifyDay);
			// model.addAttribute("today", today);
			// // 判断页面是否进行上传操作，是否可以删除、编辑
			// if (today >= beginDay && today <= endDay) {
			// // 今天在系统配置允许修改时间内，可以操作
			// model.addAttribute("impFlag", SysCode.SUCCESS);
			// } else {
			// model.addAttribute("impFlag", SysCode.FAILED);
			// }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "point/pointImport_list";
	}

	/**
	 * 数据导入到数据库中
	 * 
	 * @param pointLogList
	 * @param msg
	 *            void
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年10月24日 下午3:59:25
	 */
	private void doExecDataToDB(List<PointImportEntity> pointImportList, StringBuffer msg) {
		if (null != pointImportList && pointImportList.size() > 0) {
			for (int i = 0; i < pointImportList.size(); i++) {
				PointImportEntity pointImport = pointImportList.get(i);
				try {
					// // 每个客户，同一操作类型，只能有一条记录
					// Map<String, Object> paramMap = new HashMap<String,
					// Object>();
					// paramMap.put("customerId", pointImport.getCustomerId());
					// paramMap.put("operateType",
					// pointImport.getOperateType());
					// paramMap.put("status", PointUseFlag.UNUSE.getId());
					// List<PointImportEntity> dbRows =
					// pointImportService.listPointImport(paramMap);
					// if (null != dbRows && dbRows.size() > 0) {
					// msg.append("已存在该记录！客户编号：").append(pointImport.getCustomerId()).append("操作类型：")
					// .append(PointImportOperateType.getNameById(pointImport.getOperateType())).append("<br/>");
					// continue;
					// }
					pointImportService.savePointImport(pointImport);
					msg.append("第").append(i + 1).append("行导入成功！客户编号：").append(pointImport.getCustomerId()).append("操作类型：")
					        .append(PointImportOperateType.getNameById(pointImport.getOperateType())).append("<br/>");
				} catch (Exception e) {
					msg.append("第").append(i + 1).append("行导入出错！客户编号：").append(pointImport.getCustomerId()).append("操作类型：")
					        .append(PointImportOperateType.getNameById(pointImport.getOperateType())).append("<br/>");
					e.printStackTrace();
				}
			}
		} else {
			msg.append("未获取到数据！");
		}

	}

	/**
	 * 开始组装数据
	 * 
	 * @Title: doGetDataFromMapList
	 * @Description:(描述)
	 * @param pointLogList
	 * @param mapList
	 * @return StringBuffer
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年10月24日 下午3:16:28
	 */
	private List<PointImportEntity> doGetDataFromMapList(List<Map<String, String>> mapList, StringBuffer msg) {
		List<PointImportEntity> pointImportList = new ArrayList<PointImportEntity>();
		PointImportEntity pointImport = null;
		String userName = getUserName();
		for (int i = 0; i < mapList.size(); i++) {
			// 获取数据
			Map<String, String> dataMap = mapList.get(i);
			String customerIdStr = dataMap.get("客户编号");
			String companyName = dataMap.get("客户单位");
			String customerName = dataMap.get("客户名称");
			String mobile = dataMap.get("手机号码");
			String optTypeStr = dataMap.get("操作类型");
			String optPointStr = dataMap.get("操作积分");
			String adjustReason = dataMap.get("原因");
			// 行信息
			String rowInfo = StringUtil.formatString("【客户编号：%s，客户单位：%s，客户名称：%s，手机号码：%s】", customerIdStr, companyName, customerName, mobile);
			// 操作类型（人工核减、人工赠送）
			Integer optType = null;

			BigDecimal optPoint = null;
			if (StringUtil.isEmpty(optPointStr)) {
				msg.append("第").append(i + 1).append("行 ").append(rowInfo).append(" 操作积分 为空！<br/>");
				continue;
			} else {
				try {
					optPoint = new BigDecimal(optPointStr);
					optPoint.setScale(2, BigDecimal.ROUND_DOWN);// 直接舍去，不四舍五入（BigDecimal.ROUND_HALF_UP
					                                            // 四舍五入）
				} catch (Exception e) {
					e.printStackTrace();
					msg.append("第").append(i + 1).append("行 ").append(rowInfo).append(" 操作积分 输入不正确！<br/>");
					continue;
				}
			}
			if (StringUtil.isEmpty(optTypeStr)) {
				msg.append("第").append(i + 1).append("行 ").append(rowInfo).append(" 操作类型 为空！<br/>");
				continue;
			} else {

				optType = PointImportOperateType.getIdByName(optTypeStr);
				if (optType.equals(-1)) {
					msg.append("第").append(i + 1).append("行 ").append(rowInfo).append(" 操作类型 输入不正确，只能是（人工核减/人工赠送）！<br/>");
					continue;
				}
			}
			if (StringUtil.isEmpty(adjustReason)) {
				msg.append("第").append(i + 1).append("行 ").append(rowInfo).append(" 原因 为空！<br/>");
				continue;
			}
			if (StringUtil.isNotNull(customerIdStr)) {
				PointEntity point = pointService.getPointByCustomerId(Long.parseLong(customerIdStr));
				if (null != point) {
					// 是否比较行信息与数据信息（客户名称，客户单位，手机号）
					pointImport = new PointImportEntity();
					pointImport.setApproveStatus(ApproveStatus.WAIT_APPROVE);
					pointImport.setIsDelete(IS_DELETE.NORMAL.getId());
					pointImport.setCustomerId(point.getCustomerId());
					pointImport.setCreater(userName);
					pointImport.setModifier(userName);
					pointImport.setOperateType(optType);
					pointImport.setOperatePoint(optPoint);
					pointImport.setStatus(PointUseFlag.UNUSE.getId());
					pointImport.setAdjustReason(adjustReason);
					pointImportList.add(pointImport);
				} else {
					msg.append("第").append(i + 1).append("行获取积分信息失败！<br/>");
					continue;
				}
			} else {
				msg.append("第").append(i + 1).append("行读取数据失败！<br/>");
				continue;
			}
		}
		return pointImportList;
	}

	/**
	 * 验证文件
	 * 
	 * @param file
	 * @param model
	 * @return boolean
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年9月26日 下午6:05:53
	 */
	private StringBuffer doCheck(MultipartFile file) {
		StringBuffer msg = new StringBuffer();
		if (null == file) {
			msg.append("未获取到传入文件内容！<br/>");
			return msg;
		}
		if (!file.getOriginalFilename().matches("^.+\\.(?i)(xlsx)$") && !file.getOriginalFilename().matches("^.+\\.(?i)(xls)$")) {
			msg.append("请传入xlsx 或 xls格式的文件！<br/>");
			return msg;
		}
		if (file.getSize() == 0) {
			msg.append("错误文件(可能是非Excel文件改后缀名导致)！<br/>");
			return msg;
		}
		if (file.getSize() > (2 * 1048576)) {
			msg.append("文件大小限制为2M！<br/>");
			return msg;
		}
		return msg;
	}

	/**
	 * 根据条件导出模版
	 * 
	 * @Title: exportTemp
	 * @Description:(描述)
	 * @param request
	 * @param response
	 * @param provinceCode
	 * @param cityCode
	 * @param areaCode
	 * @param customerLevel
	 *            void
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年10月23日 下午8:18:10
	 */
	@RequestMapping("/exportTemp")
	public void exportTemp(HttpServletRequest request, HttpServletResponse response, String provinceCode, String cityCode, String areaCode,
	        String customerLevel, Integer operateType) {
		try {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("customerLevel", customerLevel);
			paramMap.put("provinceCode", provinceCode);
			paramMap.put("cityCode", cityCode);
			paramMap.put("areaCode", areaCode);
			java.util.List<PointEntity> pointList = pointService.listPoint(paramMap);

			String operateTypeName = PointOperateType.getNameById(operateType);

			List<String> headNames = new ArrayList<String>();
			headNames.add("客户编号");
			headNames.add("客户单位");
			headNames.add("客户名称");
			headNames.add("手机号码");
			headNames.add("操作类型");
			headNames.add("操作积分");
			headNames.add("原因");

			List<String> fieldNames = new ArrayList<String>();
			fieldNames.add("customerId");
			fieldNames.add("companyName");
			fieldNames.add("customerName");
			fieldNames.add("mobile");
			fieldNames.add("operateType");
			fieldNames.add("point");
			fieldNames.add("adjustReason");

			List<Map<String, Object>> dataMap = null;
			if (null != pointList && pointList.size() > 0) {
				dataMap = new ArrayList<Map<String, Object>>();
				for (PointEntity point : pointList) {
					Map<String, Object> proMap = new HashMap<String, Object>();
					proMap.put("customerId", point.getCustomerId());
					proMap.put("companyName", point.getCompanyName());
					proMap.put("customerName", point.getCustomerName());
					// 手机号中间4位换成*（18712345678 --》 187****5678）
					String mobile = point.getMobile().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
					proMap.put("mobile", mobile);
					proMap.put("operateType", operateTypeName);
					proMap.put("point", "");
					proMap.put("adjustReason", "");
					dataMap.add(proMap);
				}
			}
			String fileName = "PointImportTemplate_" + UUIDUtil.generateInteger(6) + ".xlsx";
			expToExcel07(request, response, headNames, fieldNames, fileName, dataMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 分页查询积分导入信息列表
	 * 
	 * @param pointImport
	 *            接收界面查询条件参数
	 * @param request
	 *            请求对象
	 * @return 返回对应的页面视图
	 * @author xu_cc
	 * @date 2017-10-20 14:19:50
	 */
	@RequestMapping("/listPointImportPage")
	@ResponseBody
	public JSONGrid listPointImportPage(PointImportEntity pointImport, HttpServletRequest request) {
		int pageNum = Integer.parseInt(request.getParameter("page").toString());
		int numPerPage = Integer.parseInt(request.getParameter("rows").toString());
		PageParam pageParam = super.getPageParam(request);
		pageParam.setPageNum(pageNum);
		pageParam.setNumPerPage(numPerPage);
		try {
			Map<String, Object> paramMap = new HashMap<String, Object>();

			paramMap.put("mobile", pointImport.getMobile());
			paramMap.put("operateType", pointImport.getOperateType());
			paramMap.put("customerName", pointImport.getCustomerName());
			paramMap.put("companyName", pointImport.getCompanyName());
			paramMap.put("approveStatus", pointImport.getApproveStatus());
			PageBean pageBean = pointImportService.listPointImportPage(pageParam, paramMap);
			return new JSONGrid(pageBean.getRecordList(), pageBean.getTotalCount());
		} catch (Exception e) {
			handleException("分页查询积分导入信息失败", logger, e);
		}
		return new JSONGrid();
	}

}
